{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<div class="p-3">
    <form class="layui-form gg-form-bar border-x" lay-filter="barsearchform" id="barsearchform">
<!--        <div class="layui-input-inline" style="width:300px;">-->
<!--            <input type="text" class="layui-input"  placeholder="ID"  name="id">-->
<!--        </div>-->
        <div class="layui-input-inline" style="width:300px;">
            <input type="text" class="layui-input"  placeholder="客户名称"  name="pName">
        </div>
        <div class="layui-input-inline" style="width:150px;">
            <input type="text" name="username"  placeholder="销售员" class="layui-input picker-one" readonly>
            <input type="text" name="uid" value="" style="display:none" />
        </div>
        <div class="layui-input-inline" style="width:300px;">
            <input type="text" class="layui-input" id="apply_time" placeholder="拜访时间" readonly name="apply_time">
        </div>

        <div class="layui-input-inline" style="width:300px;">
            <input type="text" class="layui-input" name="text"  placeholder="沟通人/职位/拜访方式/洽谈事项"  >
        </div>

        <div class="layui-input-inline" style="width:150px;">
            <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform"><i class="layui-icon layui-icon-search mr-1"></i>搜索</button>
            <button type="reset" class="layui-btn layui-btn-reset" lay-filter="reset">清空</button>
        </div>
    </form>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script type="text/html" id="toolbarDemo">
    <a href="javascript:" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="add">添加</a>
    	<a href="javascript:" class="layui-btn layui-btn-danger layui-btn-sm" lay-event="dels">删除</a>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool','employeepicker','laydatePlus'];
    function gouguInit() {
        var form = layui.form,table = layui.table, tool = layui.tool ,element=layui.element,laydatePlus = layui.laydatePlus;

        //日期范围
        var apply_time = new laydatePlus({'target':'apply_time'});

        layui.laydate.render({
            elem:"#bTime"
        })
        layui.laydate.render({
            elem:"#eTime"
        })
        element.on('tab(tab)', function(data){
            $("#barsearchform")[0].reset();
            layui.pageTable.reload({where:{status:data.index},page:{curr:1}});
            $('[name="status"]').val(data.index);
            return false;
        });

        //监听搜索提交
        form.on('submit(webform)', function(data) {
            layui.pageTable.reload({
                where: data.field,
                page: {curr: 1}
            });
            return false;
        });
        $('[lay-filter="clear"]').on('click',function(){
            setTimeout(function(){
                $('[lay-filter="webform"]').click();
            },10)
        });

        layui.pageTable = table.render({
            elem: '#test'
            ,toolbar: '#toolbarDemo'
            ,defaultToolbar: false
            ,title:'拜访记录'
            ,url: "{:url('index')}"
            ,page: true //开启分页
            ,limit: 20
            ,cellMinWidth: 80
            ,cols: [[
                {type: 'checkbox', fixed: 'left' },
                {field:'id',width:80, title: 'ID号', align:'center'}
                ,{field:'pName',title: '客户名称',width:90,align:'center'}
                ,{field:'vName',title: '沟通人姓名',width:90,align:'center'}
                ,{field:'vJob',title: '沟通人职位',width:120,align:'center'}
                ,{field:'vTime',title: '拜访时间',width:150,align:'center'}
                ,{field:'vType',title: '拜访方式',width:120,align:'center'}
                ,{field:'saleUser',title: '销售员',width:120,align:'center'}
                ,{field:'content',title: '洽谈事项'}
                ,{width:120,fixed: 'right',title: '操作', align:'center',templet: function(d){
                	var btn='<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>';
                	return btn;
                }}
            ]]
        });

        table.on('tool(test)',function (obj) {
        	if(obj.event === 'edit'){
        		tool.side("{:url('add')}?id="+obj.data.id);
        	}
        });
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            console.log(checkStatus)
            switch(obj.event){
                case 'add':
                    tool.side("{:url('add')}");
                    break;
                case 'dels':
                    var data = checkStatus.data;
                    var ids=[]
                    if (data.length){
                        data.forEach(function (value,index) {
                            console.log('value',value)
                            ids.push(value.id)
                        })
                        layer.confirm('确定要删除吗?', {icon: 3, title: '提示'}, function (index) {
                            let callback = function (e) {
                                layer.msg(e.msg);
                                if (e.code == 0) {
                                    layui.pageTable.reload();
                                }
                            }
                            httpRequest("{:url('delete')}", {id: ids.join(',')}, callback);
                            layer.close(index);
                        });

                    }else {
                        layer.msg('请选择数据');
                    }

                    break;

            };
        })
    }
</script>
{/block}
<!-- /脚本 -->